package com.wj.opratorlog.Emums;

import com.google.common.collect.Lists;
import com.wj.opratorlog.pojo.OperationLogReq;
import com.wj.opratorlog.service.OperatorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.Assert;

import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

/**
 * 操作类型
 */
@Slf4j
public enum ActionEnum   implements OperatorService {
    ADD("C", "新增"){
        @Override
        public void saveLog(OperationLogReq operationLogReq) {
              log.info("新增操作日志");
        }
        @Override
        public CompletableFuture<String> execute(String value) {
            log.info("新增操作日志111111111111111");
            System.out.println("新增操作日志111111111111111");
            return null;
        }
    },
    DEL("D", "删除"){
        @Override
        public void saveLog(OperationLogReq operationLogReq) {
        }
        @Override
        public CompletableFuture<String> execute(String value) {
            System.out.println(value);
            return null;
        }
    },
    EDIT("U", "修改"){

        @Override
        public void saveLog(OperationLogReq operationLogReq) {

        }
        @Override
        public CompletableFuture<String> execute(String value) {
            System.out.println(value);
            return null;
        }
    };

    private String code;
    private String desc;

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    ActionEnum(String code, String desc) {

        this.code = code;
        this.desc = desc;
    }

  public   static ActionEnum getOneEmum(String   str){

      Map<String, ActionEnum>  map= Arrays.stream(ActionEnum.values()) .collect(Collectors.toMap(ActionEnum::getCode, e -> e));
      Assert.notNull(map.get(str) ,"未找到对应的枚举类型");

      return  map.get(str);
    }


}
